#include "system.h"

extern unsigned int Foto;
extern unsigned int Power;
extern unsigned char PowerEn;
extern unsigned char FotoEn;

void Init(void)
{
OSCCON = 0b01010000;
OPTION = 0b00000010;
INTCON = 0b10100000;

TRISA = TRIS_A;
TRISB = TRIS_B;
TRISC = TRIS_C;
TRISD = TRIS_D;
TRISE = TRIS_E;

CM1CON0 = 0;
CM2CON0 = 0;
CM2CON1 = 0;

ADCON0 = 0b00000001;
ADCON1 = 0b00110000;
ANSEL  = 0b00001111;
ANSELH = 0;
ADFM = 0;

TXSTA = RCSTA = BAUDCTL = 0;
TXEN = 1;

BRGH = 0;
BRG16 = 0;
SPBRG = 1;
SPEN = 1;
//SSPMode(MASTER_MODE);
}

unsigned char DelTimer;

void interrupt
Int(void)
{
unsigned char TmpTimer;

if (T0IF)
	{
	T0IF=0;
	TmpTimer = (DelTimer++)&0b00001111;
	switch (TmpTimer)
		{
		case 0:
//			Led_Power ^= 1;
			ADCON0 = 0b00000001;
			break;
		case 1:
			ADCON0 = 0b00000011;
			break;
		case 2:
			Led = 1;
		    Power = ADRESH;		
			PowerEn = 1;
			ADCON0 = 0b00000101;
			break;
		case 3:
			ADCON0 = 0b00000111;
			break;
		case 4:
		    Foto = ADRESH;
			FotoEn = 1;
			Led = 0;
			break;
		}
	}
}





